package com.cqndt.disaster.device.service.impl;

import java.util.Map;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.jdbc.core.JdbcTemplate;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.cqndt.disaster.device.service.TabAlarmConfigService;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author lgb
 * @date 2020-8-29
 * @说明   告警配置
 **/
@Service
public class TabAlarmConfigServiceImpl implements TabAlarmConfigService{

	@Resource
	private JdbcTemplate jdbcTemplate;

	/**
	 * @param deviceNo 设备编号
	 * @return 根据设备编号查询配置列表
	 **/
	@Override
	@Transactional(readOnly=true)
	public List<Map<String,Object>> findListByNo(String deviceNo){
		String sql="SELECT ac.device_no as deviceNo,ac.* FROM `alarm_config`"
				+ " ac where device_no='"+deviceNo+"';";
		List<Map<String,Object>> list=jdbcTemplate.queryForList(sql);
		return list;
	}
	/**
	 * @param list
	 * @return 编辑list数据
	 **/
	@Override
	@Transactional(rollbackFor=RuntimeException.class)
	public void updateConfig(JSONArray list) {
		for(int i=0;i<list.size();i++) {
			JSONObject json = list.getJSONObject(i);
			Integer days = json.getInteger("days");
			String value = json.getString("value");
			Integer id = json.getInteger("id");
			String sql="update alarm_config set days="+days+",value='"+value
			+"' where id = "+id;
			jdbcTemplate.update(sql);
		}
	}
	
	
	
	
}